<template>
	<view class="c-wrap pointer" v-if="userInfo">
		<ice-header :account="userInfo.nickname"></ice-header>
		<view style="margin: 30rpx 30rpx;">
			

			<view class="part" v-for="(item,idx) in goods" :key="idx">
				<view class="title">{{item.name}}</view>
				<view class="intro">{{item.desc}}</view>
				<view class="ipt">
					<input type="number" v-model="item.money">
					<view class="type">USDT</view>
				</view>
				<view class="balance">{{lang.余额}} : {{userInfo.money}} USDT</view>
				<view class="buy" v-if="item.can_buy" @click="buy(item.id,item.money)">{{lang.购买}}</view>
				<view class="buy not" v-else>{{lang.条件未达成}}</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				userInfo: null,
				goods:[],
			}
		},
		computed: {
			nowLang() {
				this.getGoods()
				return uni.getLocale();
			},
			lang() {
				return {
					"余额":this.$t("余额"),
					"购买":this.$t("购买"),
					"条件未达成":this.$t("条件未达成"),
				}
			},
		},
		async onLoad(e) {
			console.log(e)
			await uni.$ice.checkLogin()
			this.getUserInfo()
			
		},
		methods: {
			goPage(url){
				uni.navigateTo({
					url:url
				})
			},
			getUserInfo() {
				let tmp = uni.getStorageSync('userInfo')
				if (tmp) {
					this.userInfo = JSON.parse(tmp)
				}
				uni.$ice.post('user/index', {}, false).then(res => {
					uni.setStorageSync('userInfo', JSON.stringify(res.data));
					this.userInfo = res.data
					if(this.userInfo.username != uni.$ice.walletAddress){
						uni.removeStorageSync("token")
						location.reload();
					}
					uni.stopPullDownRefresh()

				}).catch(err => {

				})
			},
			getGoods() {
				this.goods = [];
				uni.$ice.post('order/goods', {}, false).then(res => {
					this.goods = res.data;
			
				}).catch(err => {
			
				})
			},
			buy(deep,money){
				uni.$ice.post('order/buy', {money:money,deep:deep}, false).then(res => {
					this.getUserInfo()
					uni.showModal({
						title:this.$t("提示"),
						content:res.msg,
						showCancel:false,
					})
							
				}).catch(err => {
							
				})
			}
		}
	}
</script>

<style scoped>


	.pointer .part {
		box-sizing: border-box;
		height: 289px;
		border-radius: 32rpx;
		box-shadow: -1px 0 3px #6c4eed, 0 -1px 2px #69bbf5, 1px 0 3px #f56971;
		margin: 0 auto;
		padding: 38rpx 46rpx 54rpx 40rpx;
		margin-top: 80rpx
	}

	.pointer .part .title {
		color: #fff;
		font-size: 32rpx;
		font-weight: 700;
		padding-bottom: 30rpx
	}

	.pointer .part .intro {
		color: #fff;
		padding-bottom: 42rpx
	}

	.pointer .part .ipt {
		width: 100%;
		box-sizing: border-box;
		height: 110rpx;
		background: rgba(29, 3, 115, .31);
		border-radius: 24rpx;
		opacity: 1;
		border: 1px solid #c625ff;
		padding-left: 40rpx;
		padding-right: 40rpx;
		display: flex;
		flex-wrap: nowrap;
		justify-content: space-between;
		align-items:center;
	}

	.pointer .part .ipt uni-input {
		color: #fff
	}

	.pointer .part .ipt .type {
		line-height: 106rpx;
		color: #fff;
		font-size: 32rpx
	}

	.pointer .part .balance {
		padding-top: 28rpx;
		color: 24rpx;
		color: #fff;
		padding-bottom: 46rpx
	}

	.pointer .part .buy {
		height: 72rpx;
		z-index: 100;
		border-radius: 58rpx;
		background-image: linear-gradient(139deg, #9125ff, #6326ff);
		text-align: center;
		color: #fff;
		line-height: 72rpx
	}

	.pointer .part .not {
		background-image: linear-gradient(139deg, #999, #666)
	}
</style>